import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'

import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

import Icons from 'unplugin-icons/vite'
import IconsResolver from 'unplugin-icons/resolver'

// https://vite.dev/config/
export default defineConfig({
  // 请求代理
  server: {
    proxy: {
      // 若是front前缀，则请求https://mock.apifox.cn/m1/2401164-0-default/front/xxx
      "/front": {
        // target: loadEnv("", process.cwd()).VITE_API_URL, // import.meta.env.VITE_API_URL
        target: "https://mock.apifox.cn/m1/2401164-0-default",
        changeOrigin: true
      },
      "/boss": {
        // target: loadEnv("", process.cwd()).VITE_API_URL,
        target: "https://mock.apifox.cn/m1/2401164-0-default",
        changeOrigin: true
      }
    }
  },
  plugins: [
    vue(),
    vueDevTools(),
    AutoImport({
      imports: ['vue', 'vue-router', 'pinia'],
      resolvers: [ElementPlusResolver(),  IconsResolver({
        prefix: 'Icon',
      })],
      eslintrc: { enabled: true }
    }),
    Icons({
      autoInstall: true,
    }),
    Components({
      resolvers: [
        IconsResolver({
          enabledCollections: ['ep'],
        }),
        ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
})
